/**
 * Created by guojianyu on 2016/1/24.
 */
var shop=angular.module('shopIndex',[]);
/*返回登录页-注销*/
shop.controller('return',function($scope){
    $scope.return=function(){
        window.location.href="/web/"
    }
})
/*网站推广*/
shop.controller('dalianIndex',function($scope){
    $scope.dalianIndex=function(){
        window.location.href="/web/dalianIndex"
    }
})
/*推广页回到shop*/
shop.controller('shop',function($scope){
    $scope.shop=function(){
        window.location.href="/web/shopIndex"
    }
})
/*最近上新*/
shop.service('recentlyNewListService', function ($http) {
    var doRequest = function () {
        return $http.get('news/list');
    }
    return {
        newList: function () {
            return doRequest();
        }
    };
});
/*热销榜*/
shop.service('hotListService', function ($http) {
    var doRequest = function () {
        return $http.get('hot/list');
    }
    return {
        hotList: function () {
            return doRequest();
        }
    };
});
/*Top|热门排行*/
shop.service('topListService', function ($http) {
    var doRequest = function () {
        return $http.get('top/list');
    }
    return {
       topList: function () {
            return doRequest();
        }
    };
});
/*热门商家*/
shop.service('hotBusinessListService', function ($http) {
    var doRequest = function () {
        return $http.get('hotBusiness/list');
    }
    return {
        hotBusinessList: function () {
            return doRequest();
        }
    };
});
/*前台页面总列表数组*/
shop.controller('shopIndexListController', function ($scope, $location, $http, recentlyNewListService,hotBusinessListService,
                                                     hotListService,topListService,$timeout) {
    /*热门商家*/
    hotBusinessListService.hotBusinessList().success(function (response) {
        $scope.hotBusinesses = response;
        $timeout(function() {
            Layout.ajaxInit('hotBusinesses');
        });
    });
    /*热销榜*/
    hotListService.hotList().success(function (response) {
        $scope.hots = response;
        $timeout(function(){
            Layout.ajaxInit('hotProduct');
        });
    });
    /*购买热销餐品*/
    $scope.buyHot=function(data){
        $scope.hot =data;
        $timeout(function(){
            Layout.initImageZoom();
        });
    };
    $scope.saveHot = function () {
        $http.post('userOrder/saveHot', $scope.hot).success(function () {
            alert("购买成功");
            //$("#hotone").modal("hide");
            $.fancybox.close();
        }).error(function () {
            alert('购买失败');
        });
    };
    /*最近上新*/
    recentlyNewListService.newList().success(function (response) {
        $scope.news = response;
        $timeout(function(){
            Layout.ajaxInit('newestProduct');
        });
    });
    /*购买最近上新餐品*/
    $scope.buyNew=function(data){
        $scope.new =data;
        $timeout(function(){
            Layout.initImageZoom();
        });
    };
    $scope.saveNews = function () {
        $http.post('userOrder/saveNews', $scope.new).success(function () {
            alert("购买成功");
        }).error(function () {
            alert('购买失败');
        });
    };

    /*Top|热门排行*/
    topListService.topList().success(function (response) {
        $scope.tops = response;
        $timeout(function(){
            Layout.ajaxInit('topProduct');
        });
    });
    /*购买top餐品*/
    $scope.buyTop=function(data){
        $scope.top =data;
        $timeout(function(){
            Layout.initImageZoom();
        });
    };
    /*购买top餐品*/
    $scope.saveTop = function () {
        $http.post('userOrder/saveTop', $scope.top).success(function () {
            alert("购买成功");
        }).error(function () {
            alert('购买失败');
        });
    };
});


